import Vue from 'vue'
import 'default-passive-events'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 引入element-ui的中文语言包
import zhCn from 'element-ui/lib/locale/lang/zh-CN' // 中文语言包//中文包

import '@/styles/index.scss' // 全局css样式申明

import App from './App'
import store from './store'
import router from './router'
// 导入我们的图标 index.js
import '@/icons' // icon
// 导入我们的权限 indexjs
import '@/permission' // permission control
// 引入echarts
import '@/utils/echarts'
// 引入form-create
import FcDesigner from '@form-create/designer'
// 引入form-create的样式

import 'bpmn-js/dist/assets/diagram-js.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn.css'
import 'bpmn-js-properties-panel/dist/assets/bpmn-js-properties-panel.css'

// 使用 form-create 和 designer
Vue.use(FcDesigner)
Vue.use(FcDesigner.formCreate)

// 全局注册ElementUI，并且设置语言包
Vue.use(ElementUI, { zhCn })

Vue.config.productionTip = false

// 创建事件总线并挂载到Vue原型上
const bus = {
  callbacks: {},
  on(event, callback) {
    if (!this.callbacks[event]) {
      this.callbacks[event] = []
    }
    this.callbacks[event].push(callback)
  },
  emit(event, ...args) {
    if (this.callbacks[event]) {
      for (let i = 0; i < this.callbacks[event].length; i++) {
        this.callbacks[event][i](...args)
      }
    }
  },
  off(event, callback) {
    if (this.callbacks[event]) {
      this.callbacks[event] = this.callbacks[event].filter(cb => cb !== callback)
    }
  }
}
Vue.prototype.$bus = bus

// eslint-disable-next-line no-new
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
